package cn.iocoder.yudao.framework.common.enums.trade;

import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.ArrayValuable;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
@Getter
@AllArgsConstructor
public enum TradeSettleMethodTypeEnum implements ArrayValuable<Integer> {

    ADMIN_NORMAL(0,"系统正常结算"),
    ADMIN_VIOLATE(1,"违约结算"),
    MEMBER_NORMAL(2,"用户正常结算"),
    MEMBER_VIOLATE(3,"用户违约结算"),
    ;

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(TradeSettleMethodTypeEnum::getType).toArray();

    /**
     * 类型
     */
    private final Integer type;
    /**
     * 描述
     */
    private final String desc;

    public static TradeSettleMethodTypeEnum getEnum(Integer type) {
        if (type == null) {
            return null;
        }
        return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
    }

    public static TradeSettleMethodTypeEnum getType(Integer loginUserType, Boolean isViolate) {
        if (isViolate && UserTypeEnum.ADMIN.getValue().equals(loginUserType)) {
            return ADMIN_VIOLATE;
        } else if (isViolate && UserTypeEnum.MEMBER_PERSON.getValue().equals(loginUserType)) {
            return MEMBER_VIOLATE;
        } else if (!isViolate && UserTypeEnum.ADMIN.getValue().equals(loginUserType)) {
            return ADMIN_NORMAL;
        } else {
            return MEMBER_NORMAL;
        }
    }

    @Override
    public Integer[] array() {
        return new Integer[0];
    }

}
